package br.com.android;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Tela2 extends Activity{
		
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.tela2);
		
		DatabaseMenuHelper DBM = new DatabaseMenuHelper(Tela2.this);
		try {
			DBM.createDatabase();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		try{
			DBM.openDatabase();
		} catch(SQLException e){
		
			throw e;
		}
		
		
		SQLiteDatabase db = DBM.getReadableDatabase();
		
		Cursor c = db.query("menu", null, null, null, null, null, null);
		
		

		Button btvoltar = (Button)findViewById(R.id.btvoltar);
		
		TextView tv = (TextView)findViewById(R.id.txt);
		//setContentView(tv);

		

		int indice = 0;
		Intent i = getIntent();
		
		if(i!=null)
			indice = getIntent().getExtras().getInt("text");
		
		
		switch(indice){
		case 1:
			c.moveToFirst();
			tv.setText(c.getString(c.getColumnIndex("wiki")));
			
			break;
		case 2:
			c.moveToFirst();
			//tv.setText(Html.fromHtml("<p style=\"text-align:justify\">"+c.getString(c.getColumnIndex("chat"))+"</p>"));
			tv.setText(c.getString(c.getColumnIndex("chat")));
			//tv.setGravity(3);
			break;
		}
	
		db.close();
		DBM.close();
		
		
		btvoltar.setOnClickListener(new View.OnClickListener(){
			public void onClick(View arg0){
				Intent it = new Intent(Tela2.this, AppMenu.class);
				startActivity(it);

			}
		});
		
	}
}
